package com.bjgzy.courselive.di.module;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bjgzy.module_couselive.R;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.entity.RightOrderInfo;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.teacher.mvp.contract.MineOrderContract;
import com.eduhzy.ttw.teacher.mvp.model.MineOrderModel;
import com.jess.arms.di.scope.ActivityScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-8-3 10:37:55
 */
@Module
public abstract class MineOrderModule {

    @Binds
    abstract MineOrderContract.Model bindMineOrderModel(MineOrderModel model);

    @ActivityScope
    @Provides
    static List<RightOrderInfo> provideList() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    static BaseQuickAdapter<RightOrderInfo, AutoBaseViewHolder> provideActivityAdapter(List<RightOrderInfo> list) {
        return new BaseQuickAdapter<RightOrderInfo, AutoBaseViewHolder>(R.layout.courselive_rv_item_mine_order, list) {
            @Override
            protected void convert(AutoBaseViewHolder helper, RightOrderInfo item) {
                TextView payStatus = helper.getView(R.id.tv_pay_status);
                payStatus.setSelected(item.getOrderStatus() == 1);
                payStatus.setText(item.getOrderStatus() == 1 ? "已购买" : "待支付");
                RightOrderInfo.ItemListBean itemListBean = item.getItemList().get(0);
                Glide.with(helper.itemView.getContext())
                        .load(itemListBean.getLogo())
                        .apply(RequestOptions.placeholderOf(R.drawable.public_img_default).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_avatar));
                helper.setText(R.id.tv_price, helper.itemView.getContext().getString(R.string.public_rmb) + itemListBean.getDoublePrice());
                helper.setText(R.id.tv_title, itemListBean.getName());
            }

        };
    }

    @ActivityScope
    @Provides
    static RecyclerView.LayoutManager provideLayoutManger(MineOrderContract.View view) {
        return new LinearLayoutManager(view.getActivity());
    }
}